import 'package:flutter/material.dart';
import 'package:flutter_jd/tools/utils/utils.dart';
import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:get/get.dart';

class GoodsDetailController extends GetxController {
  GoodsDetailController({required this.arguments});
  final Map arguments;

  final appBarAlpha = RxDouble(0); // 透明值
  final pictureIndex = RxInt(1); // 图片位置
  double appbarScrollOffset = 150; // 滚动最大距离

  List imgList = [
    'https://www.qiniu.lingchen.kim/flutter_jd_goods_1.jpg',
    'https://www.qiniu.lingchen.kim/1831cb31ecb63f24.jpg%21q70.dpg.webp',
    'https://www.qiniu.lingchen.kim/9f224334f56f18ed.jpg%21q70.dpg.webp',
    'https://www.qiniu.lingchen.kim/5f8bb1ac4366f237.jpg%21q80.dpg.webp',
    'https://www.qiniu.lingchen.kim/5bc09154Ne75821dd.jpg%21q70.dpg.webp',
    'https://www.qiniu.lingchen.kim/16b30c715fcfc26b.jpg%21q70.dpg.webp',
    'https://www.qiniu.lingchen.kim/eb5b88202363a611.jpg%21q80.dpg.webp',
    'https://www.qiniu.lingchen.kim/59755188N08ffd2e1.jpg%21q80.dpg.webp',
    'https://www.qiniu.lingchen.kim/f8cbb20c88979da3.jpg%21q80.dpg.webp',
  ];

  final PageController pageController = PageController(keepPage: false);

  @override
  void onInit() {
    super.onInit();
    Utils.hideStatus();
  }

  @override
  void onClose() {
    super.onClose();
    Utils.showStatus();
  }

  onScroll(offset) {
    double alpha = offset / appbarScrollOffset;
    if (alpha < 0) {
      alpha = 0;
    } else if (alpha > 1) {
      alpha = 1;
    }
    appBarAlpha.value = alpha;
  }

  onPageChanged(index) {
    pictureIndex.value = index + 1;
  }
}
